/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package rg1autoboothapp;

/**
 *
 * @author apple
 */
public class AutoBooth {
    
    private int count;
    
    private Coin returnCoin;

    public AutoBooth(int count) {
        this.count = count;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public Coin getReturnCoin() {
        return returnCoin;
    }

    public void setReturnCoin(Coin returnCoin) {
        this.returnCoin = returnCoin;
    }
    
    public Drink sellDrink(Coin coin,String type)
    {
        if(coin.getValue()==5)
        {
            this.count++;
            return new Drink(type);
        }
       else
        {
            this.returnCoin=returnCharge(coin);
            if(this.returnCoin.equals(coin))
            {
                return null;
            }
            else
            {
               return new Drink(type);
            }
        }
    }
    
    private Coin returnCharge(Coin coin)
    {
        if(this.count>0)
        {
            this.count--;
            return new Coin(5);
        }
        else
        {
            return coin;
        }
    }
    
}
